<template>
	<view class="content">
		<view class="four">
			<view class="u-flex" @tap="goDetails">
				<view class="four_left">
					<image
						src="https://img2.baidu.com/it/u=1070586782,3628032787&fm=253&fmt=auto&app=138&f=JPEG?w=321&h=500"
						mode=""></image>
				</view>
				<view class="four_right">
					<view class="four_right1">
						<image
							src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR9Pykq71TSey2UAmqZ5vSBQkvt7s6hKyEzOg&usqp=CAU"
							mode=""></image>
					</view>
					<view class="four_right2">
						<image
							src="https://img2.baidu.com/it/u=2617685468,2154034022&fm=253&fmt=auto&app=138&f=JPEG?w=642&h=500"
							mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="wrap_two">
			<!-- <u-button @click="clear">清空列表</u-button> -->
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @tap="goDetails">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.newprice}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close"
							@click="remove(item.id)">
						</u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index"  @tap="goDetails">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.newprice}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close"
							@click="remove(item.id)">
						</u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flowList: [],
				loadStatus: 'loadmore',
				"imglist": [{
						"id": 4,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": 5.2,
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRP0k1O6spa8DBYQfHT5MkVljGIKU8NVpIXKg&usqp=CAU",
					},
					{
						"id": 5,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSkxP6Cpwxekgyu16FirzoLeFM-hsOr-MUH5Q&usqp=CAU",
					},
					{
						"id": 6,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQZHTs8_zvcAJG8ctoGGZcT8kTIercadOMcqQ&usqp=CAU",
					},
					{
						"id": 7,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://img2.baidu.com/it/u=1429742129,3388883706&fm=253&fmt=auto&app=138&f=JPEG?w=692&h=500",
					},
					{
						"id": 8,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "http://img30.360buyimg.com/popWareDetail/jfs/t1/157113/2/18133/155596/60700a98E7477c3f2/0abc30951c082385.jpg"
					},
					{
						"id": 9,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ1JWZ80M3_N-MaUW75SQYJUynMhzK_6nPcgA&usqp=CAU"
					},
					{
						"id": 10,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://img2.baidu.com/it/u=2617685468,2154034022&fm=253&fmt=auto&app=138&f=JPEG?w=642&h=500"
					},
					{
						// 这里图片不存在，会加载失败，显示错误的占位图
						"id": 11,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDHW_fbXKderQskwimZabpMiwT5Q1GMUw_WA&usqp=CAU",
					},
					{
						"id": 12,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQTc5kEHFBzyqC41xKvOUwaMEaqp1bn-ywW7A&usqp=CAU"
					},
					{
						"id": 13,
						"name": '最新版钢笔款2023年必须买，不买你就不行了,爆款疯狂GG008大姨绒毛大款2020年必须买,不买你就亏本了，爆款直售，走过路过不要错过！',
						"newprice": 128,
						"oldprice": 98,
						"discount": '5.2',
						"shop": '雪梨旗舰店',
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQPZuozypl5cKmVSDZTOJHiirpMqZ5_nyV-rw&usqp=CAU"
					}
				],
			}
		},
		onLoad() {
			this.addRandomData();
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				this.addRandomData();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		methods: {
			addRandomData() {
				for (let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.imglist.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.imglist[index]))
					item.id = this.$u.guid();
					this.flowList.push(item);
				}
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			},
			goDetails(){
				uni.navigateTo({
					url:'/pages/details/details'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		margin-top: 20rpx;
	}
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 34rpx;
		margin-top: 5px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		color: #333333;
		word-break: break-all;
		padding: 6rpx 0;
		// color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}

	.four {
		width: 96%;
		margin: 0rpx auto;

		// background-color: red;
		.four_left {
			width: 50%;
			height: 600rpx;
			background-color: #00ffff;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.four_right {
			width: 50%;
			height: 600rpx;
			background-color: #5500ff;

			.four_right1 {
				height: 300rpx;
				background-color: mediumvioletred;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.four_right2 {
				height: 300rpx;
				background-color: pink;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>
